<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script src="js/lodash-4.17.21.js"></script>
		<script type="text/javascript">
					var arr = [1, 1, 1, 1, 2, 2, 2, 3, 3];
					var obj = {};
					for (var i = 0; i < arr.length; i++) {
						if (!obj[arr[i]]) {
							obj[arr[i]] = 1;
						}
						else {
							obj[arr[i]]++
						}
					}
					var maxValue = 0;
					var maxStr = arr[0];
					for (var i in obj) {
						if (obj[i] > maxValue) {
							maxValue = obj[i];
							maxStr = i;
						}
					}
					console.log("在数组中出现最多的元素是:" + maxStr + "出现" + maxValue + "次");

			// 		var str = '';
			// 		for (i = 0; i < 10; i ++) {
			// 			str += 'NUM ONE <br>';
			// 		}
			// 		document.write(str)

			// 		var n = parseInt(window.prompt('请输入n的值', 0));
			// 		var i =1;
			// 		var max = parseInt(prompt('请输入第 + 'i' + 数, 1));
			// 		var num;
			// 		while (i < n) {
			// 			i ++;
			// 			num = parseInt(prompt('请输入第 + 'i' + 数, 1));
			// 			if (max < num) {
			// 				max = num;
			// 			}
			// 		}

			// 		function c(a,b) {
			// 			var tem;
			// 			tem = a;
			// 			a = b;
			// 			b = a;
			// 			alert ('a =' + a + ',b =' + b);
			// 		}
			// 		c(3, 7)

			// 			var arr = new Array(5);
			// 			arr[7] = 9;
			// 			console.log(arr.length);

			var arr = [4, 6, 5, 68, 8, 8, 56, 979, 879];
			var str = ''
			// for (var i = 0; i<arr.length; i++) {
			// 	str += arr[i];
			// }
			// 	document.write('第' + (i + 1) + '个元素' + arr[i] + '<br>');

			// 			for (var index in arr) {
			// 				str += arr[index];
			// 			}
			// 				document.write('第' + (parseInt(index) + 1) + '个元素' + str + '<br>');

			var arr = [4, 6, 5, 68, 8, 8, 56, 979, 879];
			for (var i = 1; i < arr.length; i++) {
				for (var j = 0; j < arr.length - i; j++) {
					if (arr[j] > arr[j + 1]) {
						var tem = arr[j];
						arr[j] = arr[j + 1];
						arr[j + 1] = tem;
					}
				}
			}
			console.log(arr);

			var arr = [10, 20, 1, 2];
			var t;
			for (var i = 0; i < arr.length; i++) {
				for (j = i + 1; j < arr.length; j++) {
					if (arr[i] > arr[j]) {
						t = arr[i];
						arr[i] = arr[j];
						arr[j] = t;
					}
				}
			}
			console.log('arr', arr); //[1, 2, 10, 20]			

			function sortNumber(a, b) {
				return a - b
			}

			// 			var arr = new Array(6)
			// 			arr[0] = "10"
			// 			arr[1] = "5"
			// 			arr[2] = "40"
			// 			arr[3] = "25"
			// 			arr[4] = "1000"
			// 			arr[5] = "1"

			var arr = [10, 5, 40, 25, 1000, 1]

			document.write(arr + "<br />")
			document.write(arr.sort(sortNumber))

			var arr = [23, 34, 3, 4, 23, 44, 333, 444];
			arr.sort(function(a, b) {
				return a - b;
			})
			console.log(arr);


			var arr = [22, 12, 3, 43, 56, 47, 4];
			arr.sort();
			console.log(arr); // [12, 22, 3, 4, 43, 47, 56]
			arr.sort(function(m, n) {
				if (m < n) return -1
				else if (m > n) return 1
				else return 0
			});
			console.log(arr); // [3, 4, 12, 22, 43, 47, 56]


			function myFunction(a, b) {
				if (a > b) {
					// return x=2;
				}
				x = a + b
			}
			myFunction(4, 3)
			console.log(x)

			// 2数组合并1个对象
			let op = [];
			let times = [30, 60];
			let timesDesc = ['30分', '1小时']
			const f1 = (key, arr) => arr.map(item => ({
				[key]: item
			}))
			const getMaxArr = (times, timesDesc) => (times.length >= timesDesc.length) ? times : timesDesc;
			const mergeArr = (oldArr, arr) => oldArr.map((item, index) => ({
				[(times.length >= timesDesc.length) ? 'times' : 'timesDesc']: item,
				...arr[index]
			}))
			let list1 = f1('times', times);
			let list2 = f1('timsDesc', timesDesc);
			op = mergeArr(getMaxArr(times, timesDesc), list2)
			console.log(op)

			{
				const arr = [1, 1, 3, 5, 6, 6, 7, 8, 8]
				// const uniqArr = [...new Set(arr)]
				// const uniqArr = _.uniq(arr)
				// const uniqueArr = arr.filter((item, index) => arr.indexOf(item) === index)
				let uniqArr = []
				const obj = {}
				arr.forEach((item, index) => {
					// if (arr.indexOf(item) === index) {
					// 	uniqArr.push(item)
					// }
					// if (uniqArr.indexOf(item) === -1) {
					if (!uniqArr.includes(item)) {
						uniqArr.push(item)
					}
					// if (!obj[item]) {
					// 	obj[item] = item
					// }
				})
				// uniqArr = Object.values(obj)
				// for (let i in arr) {
				// 	if (arr.indexOf(arr[i]) == i) {
				// 		uniqArr.push(arr[i])
				// 	}
				// }
				document.write("<br />")
				document.write(uniqArr)
			}
		</script>
	</body>
</html>